<?php

$select = "select * from klient where id = ".$_GET["editk"];

if (!$res_klient = MySQL_Query($select, $spojeni))
{
  // log
  logging("".date("Y/m/d H:m:s").": ".__FILE__.": [".__LINE__."] Error ".MySQL_ErrNo().": ".MySQL_Error($spojeni)."\n");
}
else
{
  if (!$pole_klient = MySQL_Fetch_Array($res_klient))
  {
    logging("".date("Y/m/d H:m:s").": ".__FILE__.": [".__LINE__."] Error ".MySQL_ErrNo().": ".MySQL_Error($spojeni)."\n");
  }
  else
  {
    $select = "select * from adresa where id = ".$pole_klient["adresa_id"];
    if (!$res_adresa = MySQL_Query($select, $spojeni))
    {
      logging("".date("Y/m/d H:m:s").": ".__FILE__.": [".__LINE__."] Error ".MySQL_ErrNo().": ".MySQL_Error($spojeni)."\n");
    }
    else
    {
      if (!$pole_adresa = MySQL_Fetch_Array($res_adresa))
      {
        logging("".date("Y/m/d H:m:s").": ".__FILE__.": [".__LINE__."] Error ".MySQL_ErrNo().": ".MySQL_Error($spojeni)."\n");
      }
      else
      {
        if ($pole_klient["adresa_id"] != $pole_klient["korespondencni_adresa_id"])
        {
          // adresy jsou stejne
          $select = "select * from adresa where id = ".$pole_klient["korespondencni_adresa_id"];
          if (!$res_k_adresa = MySQL_Query($select, $spojeni))
          {
            logging("".date("Y/m/d H:m:s").": ".__FILE__.": [".__LINE__."] Error ".MySQL_ErrNo().": ".MySQL_Error($spojeni)."\n");
          }
          else
          {
            if (!$pole_k_adresa = MySQL_Fetch_Array($res_k_adresa))
            {
              logging("".date("Y/m/d H:m:s").": ".__FILE__.": [".__LINE__."] Error ".MySQL_ErrNo().": ".MySQL_Error($spojeni)."\n");
            }
          }
        }
        else
        {
          // adresy jsou ruzne
        }
      }
    }
    
    $select = "select * from kontaktni_osoba where klient_id = ".$pole_klient["id"];
    if (!$res_ko = MySQL_Query($select, $spojeni))
    {
      logging("".date("Y/m/d H:m:s").": ".__FILE__.": [".__LINE__."] Error ".MySQL_ErrNo().": ".MySQL_Error($spojeni)."\n");
    }
    else
    {
      if (!$pole_ko = MySQL_Fetch_Array($res_ko))
      {
        logging("".date("Y/m/d H:m:s").": ".__FILE__.": [".__LINE__."] Error ".MySQL_ErrNo().": ".MySQL_Error($spojeni)."\n");
      }
      else
      {
        //
        //  ADRESA KONTAKTNI OSOBY
        //
        $select = "select * from adresa where id = ".$pole_ko["adresa_id"];
        if (!$res_ko_adr = MySQL_Query($select, $spojeni))
        {
          logging("".date("Y/m/d H:m:s").": ".__FILE__.": [".__LINE__."] Error ".MySQL_ErrNo().": ".MySQL_Error($spojeni)."\n");
        }
        else
        {
          if (!$pole_ko_adr = MySQL_Fetch_Array($res_ko_adr))
          {
            logging("".date("Y/m/d H:m:s").": ".__FILE__.": [".__LINE__."] Error ".MySQL_ErrNo().": ".MySQL_Error($spojeni)."\n");
          }
        }

        //
        //  KORESPONDENCNI a FAKTURACNI adresa
        //
        if ($pole_ko["adresa_fakturacni_id"] != 0)
        {
          $select = "select * from adresa where id = ".$pole_ko["adresa_fakturacni_id"];
          if (!$res_ko_fadr = MySQL_Query($select, $spojeni))
          {
            logging("".date("Y/m/d H:m:s").": ".__FILE__.": [".__LINE__."] Error ".MySQL_ErrNo().": ".MySQL_Error($spojeni)."\n");
          }
          else
          {
            if (!$pole_ko_fadr = MySQL_Fetch_Array($res_ko_fadr))
            {
              logging("".date("Y/m/d H:m:s").": ".__FILE__.": [".__LINE__."] Error ".MySQL_ErrNo().": ".MySQL_Error($spojeni)."\n");
            }
          }
        }

        if ($pole_ko["adresa_korespondencni_id"] != 0)
        {
          // adresy jsou stejne
          $select = "select * from adresa where id = ".$pole_ko["adresa_korespondencni_id"];
          if (!$res_ko_kadr = MySQL_Query($select, $spojeni))
          {
            logging("".date("Y/m/d H:m:s").": ".__FILE__.": [".__LINE__."] Error ".MySQL_ErrNo().": ".MySQL_Error($spojeni)."\n");
          }
          else
          {
            if (!$pole_ko_kadr = MySQL_Fetch_Array($res_ko_kadr))
            {
              logging("".date("Y/m/d H:m:s").": ".__FILE__.": [".__LINE__."] Error ".MySQL_ErrNo().": ".MySQL_Error($spojeni)."\n");
            }
          }
        }
      }
    }
  }
}

?>

